<template>
  <div>
    <!--引用表格-->
   <BasicTable @register="registerTable" :rowSelection="rowSelection">
     <!--插槽:table标题-->
      <template #tableTitle>
          
      </template>
      <template #statusSlot="{ record }">
        <Tag v-if="record.status==0" color="orange">待审核</Tag>
        <Tag v-if="record.status==1" color="green">通过</Tag>
        <Tag v-if="record.status==2" color="red">未通过</Tag>
      </template>
	  <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)"/>
      </template>
	  <template #sourcePersonInfo="{ record }">
        {{record.sourcePersonName + '(' + record.sourcePersonCode + ')'}}
      </template>
	  <template #sourceClazzInfo="{ record }">
		<div>
			<div>{{ record.sourcePersonWorkDate }}</div>
			<div>{{record.sourcePeriodName + ':' + record.sourcePeriodWorkTime + '~'+ record.sourcePeriodLeaveTime}}</div>
		</div>
      </template>
	  
	  <template #targetPersonInfo="{ record }">
        {{record.targetPersonName + '(' + record.targetPersonCode + ')'}}
      </template>
	  <template #targetClazzInfo="{ record }">
		<div>
			<div>{{ record.targetPersonWorkDate }}</div>
			<div>{{record.targetPeriodName + ':' + record.targetPeriodWorkTime + '~'+ record.targetPeriodLeaveTime}}</div>
		</div>
      </template>
      <!--字段回显插槽-->
      <template v-slot:bodyCell="{ column, record, index, text }">
      </template>
    </BasicTable>
    
    <AttEventRegModalShowAudit @register="registerModalShowAudit" @success="handleSuccess"></AttEventRegModalShowAudit>
    <AttScheduleSwaprecModal @register="registerModalHandleAudit" @success="handleSuccess"></AttScheduleSwaprecModal>
  </div>
</template>

<script lang="ts" name="attendance-attScheduleSwaprec" setup>
  import {ref, reactive, computed, unref} from 'vue';
  import {BasicTable, useTable, TableAction} from '/@/components/Table';
  import {useModal} from '/@/components/Modal';
  import { Tag, Avatar } from 'ant-design-vue';
  import { useListPage } from '/@/hooks/system/useListPage'
  import AttEventRegModalShowAudit from '/@/views/attendance/attEventReg/components/AttEventRegModalShowAudit.vue'

  import AttScheduleSwaprecModal from './components/AttScheduleSwaprecModal.vue'
  import {columns, searchFormSchema} from './AttScheduleSwaprec.data';
  import {list, audit} from './AttScheduleSwaprec.api';
  import { downloadFile } from '/@/utils/common/renderUtils';
  import { useUserStore } from '/@/store/modules/user';
  const [registerModalShowAudit, {openModal:openModalShowAudit}] = useModal();
  const [registerModalHandleAudit, {openModal}] = useModal();
  const queryParam = reactive<any>({});
  const checkedKeys = ref<Array<string | number>>([]);
  const userStore = useUserStore();
  //注册model
  //注册table数据
  const { prefixCls,tableContext} = useListPage({
      tableProps:{
           title: '换班审核',
           api: list,
           columns,
           canResize:false,
           formConfig: {
              //labelWidth: 120,
              schemas: searchFormSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:false,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
              ],
            },
           actionColumn: {
               width: 120,
               fixed:'right'
            },
            beforeFetch: (params) => {
              return Object.assign(params, queryParam);
            },
      }
  })

  const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext

   /**
    * 审核事件
    */
  function handleAudit(record: Recordable) {
     openModal(true, {
       record,
       isUpdate: true,
       showFooter: true,
     });
   }
   function handleShowAudit(record: Recordable) {
    record.eventType = Number(record.eventType)
    record.isAudit = 1
    openModalShowAudit(true, {
      record,
      applyCode:'attschedule',
      isUpdate: false,
      showFooter: false,
    });
  }
   /**
    * 成功回调
    */
  function handleSuccess() {
      (selectedRowKeys.value = []) && reload();
   }
  
  function getTableAction(record){
      let menus = [];
      if(record.applyResultId) {
        menus.push({label: '审核',onClick: handleAudit.bind(null, record)});
      }
      menus.push({label: '流程显示',onClick: handleShowAudit.bind(null, record)});
      return menus; 
   }

</script>

<style scoped>

</style>